﻿//============================================================
//write by bxl at 2021-06-13 22:10:28
//============================================================



using System.Collections.Generic;
using System;
using BCService.Utils;
using BCCommon;
using BCData.CRM.BigCustomerTradeAnalysis;
using BCDto.CRM.BigCustomerTradeAnalysis;
using BCEntity.CRM.BigCustomerTradeAnalysis;
using BCDto.Sim.Admin.Admin;

namespace BCService.CRM.BigCustomerTradeAnalysis
{
    public class BigCustomerTradeAnalysisService : IBigCustomerTradeAnalysisService
    {
        #region var
        private readonly IDatabaseContext databaseContext;
        private IBigCustomerTradeAnalysisData bigCustomerTradeAnalysisData;


        #endregion

        #region 构造函数
        public BigCustomerTradeAnalysisService(IBigCustomerTradeAnalysisData bigCustomerTradeAnalysisData, IDatabaseContext databaseContext)
        {
            this.bigCustomerTradeAnalysisData = bigCustomerTradeAnalysisData;
            this.databaseContext = databaseContext;
        }
        #endregion

        #region Add
        /// <summary>
        /// 添加新大客户交易分析纪录
        /// </summary>
        /// <param name="bigCustomerTradeAnalysisRequestDto"></param>
        /// <param name="admin"></param>
        /// <returns></returns>
        public BigCustomerTradeAnalysisDto Add(BigCustomerTradeAnalysisRequestDto bigCustomerTradeAnalysisRequestDto, AdminDto admin)
        {
            return bigCustomerTradeAnalysisData.InsertAsync(bigCustomerTradeAnalysisRequestDto.As<BigCustomerTradeAnalysisEntity>()).GetAwaiter().GetResult().As<BigCustomerTradeAnalysisDto>();
        }
        #endregion

        #region update
        /// <summary>
        /// 修改大客户交易分析记录
        /// </summary>
        /// <param name="bigCustomerTradeAnalysisDto"></param>
        /// <param name="admin"></param>
        /// <returns></returns>
        public BigCustomerTradeAnalysisDto Update(BigCustomerTradeAnalysisDto bigCustomerTradeAnalysisDto, AdminDto admin)
        {
            return bigCustomerTradeAnalysisData.UpdateAsync(bigCustomerTradeAnalysisDto.As<BigCustomerTradeAnalysisEntity>()).GetAwaiter().GetResult().As<BigCustomerTradeAnalysisDto>();

        }
        #endregion

        #region Delete
        /// <summary>
        /// 删除大客户交易分析记录
        /// </summary>
        /// <param name="bigCustomerTradeAnalysisId"></param>
        /// <returns></returns>
        public void Delete(long bigCustomerTradeAnalysisId)
        {
            bigCustomerTradeAnalysisData.DeleteAsync(bigCustomerTradeAnalysisId).GetAwaiter().GetResult();

        }
        #endregion

        #region GetByBigCustomerTradeAnalysisId
        /// <summary>
        /// 获取大客户交易分析记录
        /// </summary>
        /// <param name="bigCustomerTradeAnalysisId"></param>
        /// <returns></returns>
        public BigCustomerTradeAnalysisDto GetById(long bigCustomerTradeAnalysisId)
        {
            var a = bigCustomerTradeAnalysisData.GetEntityAsync(bigCustomerTradeAnalysisId).GetAwaiter().GetResult();
            return a.As<BigCustomerTradeAnalysisDto>();
        }
        #endregion

        #region GetList  获取大客户交易分析记录--[分页]
        public PageableList<BigCustomerTradeAnalysisDto> GetList(int pageIndex, int pageSize)
        {
            int fCount = 0;
            IEnumerable<BigCustomerTradeAnalysisEntity> fList;

            (fList, fCount) = bigCustomerTradeAnalysisData.GetListAsync(pageIndex, pageSize).GetAwaiter().GetResult();

            return new PageableList<BigCustomerTradeAnalysisDto>()
            {
                Count = fCount,
                Items = fList.As<IEnumerable<BigCustomerTradeAnalysisDto>>(),
                PageIndex = pageIndex,
                PageSize = pageSize,
                ServerTime = DateTime.Now,
            };
        }
        #endregion
    }
}